package com.dianxin.farm.api;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.dianxin.farm.entity.BannerNews;
import com.dianxin.farm.filter.AuthorCheck;
import com.dianxin.farm.request.common.PageRequest;
import com.dianxin.farm.service.CurrentLoginService;
import com.dianxin.farm.service.IBannerNewsService;
import com.dianxin.farm.util.web.ApiResponse;
import com.dianxin.farm.util.web.ApiResponseUtils;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.time.LocalDateTime;
import java.util.List;

/**
 * <p>
 * 橱窗信息表 前端控制器
 * </p>
 *
 * @author xukai
 * @since 2020-09-14
 */
@RestController
@RequestMapping(value = "/bannerNews", method = RequestMethod.POST, produces = "application/json;charset=utf-8")
@AuthorCheck
@Api(description = "公告控制器")
public class BannerNewsController {
    @Resource
    private IBannerNewsService bannerNewsService;
    @Resource
    private CurrentLoginService currentLoginService;


    @ApiOperation("公告分页列表")
    @RequestMapping(value = "/bannerPages")
    @ResponseBody
    @AuthorCheck
    public ApiResponse<PageInfo<BannerNews>> bannerPages(@Valid @RequestBody PageRequest request) {
        PageHelper.startPage(request.getPage(), request.getSize());
        QueryWrapper wrapper = new QueryWrapper();
        wrapper.eq( "shelf", 1);
        wrapper.orderByDesc("id");
        List<BannerNews> newsList = bannerNewsService.list(wrapper);
        return ApiResponseUtils.success(new PageInfo<>(newsList));
    }



}
